home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / Wipeout / source / privateallocvec.c < prev    next >
C/C++ Source or Header  |  1998-04-16  |  2KB  |  85 lines

  1. /*
  2.  * $Id: privateallocvec.c 1.6 1998/04/16 10:25:42 olsen Exp olsen $
  3.  *
  4.  * :ts=4
  5.  *
  6.  * Wipeout -- Traces and munges memory and detects memory trashing
  7.  *
  8.  * Written by Olaf `Olsen' Barthel <olsen@sourcery.han.de>
  9.  * Public Domain
  10.  */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "global.h"
  14. #endif    /* _GLOBAL_H */
  15.  
  16. /******************************************************************************/
  17.  
  18. #include "installpatches.h"
  19.  
  20. /******************************************************************************/
  21.  
  22. APTR
  23. PrivateAllocVec(ULONG byteSize,ULONG attributes)
  24. {
  25.     APTR result;
  26.  
  27.     /* allocate memory through AllocMem(); but if AllocMem()
  28.      * has been redirected to our code, we still want to use
  29.      * the original ROM routine
  30.      */
  31.  
  32.     if(OldAllocMem != NULL)
  33.     {
  34.         result = (*OldAllocMem)(sizeof(ULONG) + byteSize,attributes,SysBase);
  35.     }
  36.     else
  37.     {
  38.         result = AllocMem(sizeof(ULONG) + byteSize,attributes);
  39.     }
  40.  
  41.     /* store the size information in front of the allocation */
  42.     if(result != NULL)
  43.     {
  44.         ULONG * size = result;
  45.  
  46.         (*size) = sizeof(ULONG) + byteSize;
  47.  
  48.         result = (APTR)(size + 1);
  49.     }
  50.  
  51.     return(result);
  52. }
  53.  
  54. VOID
  55. PrivateFreeVec(APTR memoryBlock)
  56. {
  57.     /* free memory allocated by AllocMem(); but if FreeMem()
  58.      * has been redirected to our code, we still want to use
  59.      * the original ROM routine
  60.      */
  61.  
  62.     if(memoryBlock != NULL)
  63.     {
  64.         ULONG * mem;
  65.         ULONG size;
  66.  
  67.         /* get the allocation size */
  68.         mem = (ULONG *)(((ULONG)memoryBlock) - sizeof(ULONG));
  69.         size = (*mem);
  70.  
  71.         /* munge the allocation */
  72.         MungMem(mem,size,DEADBEEF);
  73.  
  74.         /* and finally free it */
  75.         if(OldFreeMem != NULL)
  76.         {
  77.             (*OldFreeMem)(mem,size,SysBase);
  78.         }
  79.         else
  80.         {
  81.             FreeMem(mem,size);
  82.         }
  83.     }
  84. }
  85.